<?php

namespace Biz\service\advertisement\apiModule;

use Doraemon\model\Position\PositionExtend;
use Doraemon\service\statSign\Basic as basicStatSign;
use Doraemon\tools\BlockType;
use Doraemon\tools\ImgUrl;
use Doraemon\tools\LinkFormat;

class Tab4WelfareAgencyBanner extends BaseModule
{

    const FORMAT_HIT = 'formatPosHit';

    public function format($hit, $uid, $userProfileExt, $statSignExt)
    {
        $response = [];
        $upgradeVersion = '5.21.0';
        foreach ($hit as $k => $v) {
            $link = $this->generateLink($v['link_type'], $v['link_params']);
            $title = $v['ext'] ? $v['ext']['title'] : '';
            $response[] = [
                'id' => intval($v['id']),
                'title' => $title,
                'sub_title' => $v['ext'] ? $v['ext']['key_word'] : '',
                'index' => intval($v['pos']),
                'banner' => empty($v['pic_id']) ? '' : ImgUrl::getUrl(ImgUrl::APPTYPE_OP, $v['pic_id'], ImgUrl::IMAGE_SIZE_OP_ORI),
                'goods_img' => empty($v['single_pic_id']) ? '' : ImgUrl::getUrl(ImgUrl::APPTYPE_OP, $v['single_pic_id'], ImgUrl::IMAGE_SIZE_OP_ORI),
                'link' => $link,
                'statSign' => $this->statSign($v, [basicStatSign::EXTEND_KEY_INDEX => $k + 1], ['title' => $title, 'link' => $link]),
            ];
        }

        return \Doraemon\tools\StatSign::versionCompatible($response, $upgradeVersion, BlockType::TYPE_BANNER, 'banner');
    }

    public function uniquePos($v): string
    {
        return $v['pos'];
    }
}